﻿import mx.utils.Delegate;

import idv.ben.picasawebservice4flash.data.*;
import idv.ben.picasawebservice4flash.sample.*;
import idv.ben.picasawebservice4flash.service.*;

class idv.ben.picasawebservice4flash.sample.Sample extends MovieClip{
	
	private var __service:PicasawebService;
	
	/**
	* 建構子
	*/
	function Sample(){
		__service = new PicasawebService();
		
		__service.addEventListener(PicasawebService.EVENT_FEED_ONLOAD, Delegate.create(this, handlerFeedOnLoad));
		__service.addEventListener(PicasawebService.EVENT_FEED_ONERROR, Delegate.create(this, handlerFeedOnError));

		__service.addEventListener(PicasawebService.EVENT_ENTRY_ONLOAD, Delegate.create(this, handlerEntryOnLoad));
		__service.addEventListener(PicasawebService.EVENT_ENTRY_ONERROR, Delegate.create(this, handlerEntryOnError));
		
		__service.loadFeed("Ben.RB.Chang");
	}
	
	private function handlerFeedOnLoad(evtObj:Object):Void{
		for(var i:String in evtObj){
			trace(i + " = " + evtObj[i]);
		}
		
		traceBasicInfo(evtObj.feed);
		traceEntryInfo(evtObj.feed, "20071005");
	}
	
	private function handlerFeedOnError(evtObj:Object):Void{
		for(var i:String in evtObj){
			trace(i + " = " + evtObj[i]);
		}
	}
	
	private function traceBasicInfo(feed:UserFeed):Void{
		trace("id = " + feed.id);
		trace("updated = " + feed.updated);
		trace("title = " + feed.title);
		trace("subtitle = " + feed.subtitle);
		trace("icon = " + feed.icon);
		trace("author_name = " + feed.author_name);
		trace("author_uri = " + feed.author_uri);
		
		trace("");
			
		trace("gphoto.user = " + feed.gphoto.user);
		trace("gphoto.nickname = " + feed.gphoto.nickname);
		trace("gphoto.thumbnail = " + feed.gphoto.thumbnail);
		trace("gphoto.quotalimit = " + feed.gphoto.quotalimit);
		trace("gphoto.quotacurrent = " + feed.gphoto.quotacurrent);
		trace("gphoto.maxPhotosPerAlbum = " + feed.gphoto.maxPhotosPerAlbum);
		
		trace("");
	}
	
	private function traceEntryInfo(feed:UserFeed, entryName:String):Void{
		for(var i:Number = 0; i<feed.entrys.length; i++){
			var entry:AlbumEntry = feed.entrys[i];
			if(entry.gphoto.name.toString() == entryName.toString()){
				trace("entry.id = " + entry.id);
				trace("entry.published = " + entry.published);
				trace("entry.updated = " + entry.updated);
				trace("entry.title = " + entry.title);
				trace("entry.summary = " + entry.summary);
				trace("entry.rights = " + entry.rights);
				trace("entry.author_name = " + entry.author_name);
				trace("entry.author_uri = " + entry.author_uri);
				
				trace("");
				
				trace("entry.gphoto.id = " + entry.gphoto.id);
				trace("entry.gphoto.name = " + entry.gphoto.name);
				trace("entry.gphoto.location = " + entry.gphoto.location);
				trace("entry.gphoto.access = " + entry.gphoto.access);
				trace("entry.gphoto.timestamp = " + entry.gphoto.timestamp);
				trace("entry.gphoto.numphotos = " + entry.gphoto.numphotos);
				trace("entry.gphoto.numphotosremaining = " + entry.gphoto.numphotosremaining);
				trace("entry.gphoto.bytesUsed = " + entry.gphoto.bytesUsed);
				trace("entry.gphoto.user = " + entry.gphoto.user);
				trace("entry.gphoto.nickname = " + entry.gphoto.nickname);
				trace("entry.gphoto.commentingEnabled = " + entry.gphoto.commentingEnabled);
				trace("entry.gphoto.commentCount = " + entry.gphoto.commentCount);
				
				trace("");

				trace("entry.media.title = " + entry.media.title);
				trace("entry.media.description = " + entry.media.description);
				trace("entry.media.keywords = " + entry.media.keywords);
				trace("entry.media.content = " + entry.media.content);
				trace("entry.media.thumbnail = " + entry.media.thumbnail);
				trace("entry.media.credit = " + entry.media.credit);
				
				trace("");
				
				
				__service.loadEntry(entry);
				
				break;
			}
		}
	}
	
	private function handlerEntryOnLoad(evtObj:Object):Void{
		for(var i:String in evtObj){
			trace(i + " = " + evtObj[i]);
		}
		
		trace("id = " + evtObj.feed.id);
		trace("updated = " + evtObj.feed.updated);
		trace("title = " + evtObj.feed.title);
		trace("subtitle = " + evtObj.feed.subtitle);
		trace("rights = " + evtObj.feed.rights);
		trace("icon = " + evtObj.feed.icon);
		trace("author_name = " + evtObj.feed.author_name);
		trace("author_uri = " + evtObj.feed.author_uri);
		
		trace("");

		trace("gphoto.id = " + evtObj.feed.gphoto.id);
		trace("gphoto.name = " + evtObj.feed.gphoto.name);
		trace("gphoto.location = " + evtObj.feed.gphoto.location);
		trace("gphoto.access = " + evtObj.feed.gphoto.access);
		trace("gphoto.timestamp = " + evtObj.feed.gphoto.timestamp);
		trace("gphoto.numphotos = " + evtObj.feed.gphoto.numphotos);
		trace("gphoto.numphotosremaining = " + evtObj.feed.gphoto.numphotosremaining);
		trace("gphoto.bytesUsed = " + evtObj.feed.gphoto.bytesUsed);
		trace("gphoto.user = " + evtObj.feed.gphoto.user);
		trace("gphoto.nickname = " + evtObj.feed.gphoto.nickname);
		trace("gphoto.commentingEnabled = " + evtObj.feed.gphoto.commentingEnabled);
		trace("gphoto.commentCount = " + evtObj.feed.gphoto.commentCount);
	
		trace("");

		//for(var i:Number = 0; i<evtObj.feed.entrys.length; i++){
		for(var i:Number = 0; i<1; i++){
			var entry:PhotoEntry = evtObj.feed.entrys[i];
			
			trace("entry.id = " + entry.id);
			trace("entry.published = " + entry.published);
			trace("entry.updated = " + entry.updated);
			trace("entry.title = " + entry.title);
			trace("entry.summary = " + entry.summary);
			trace("entry.content = " + entry.content);
				
			trace("");
	
			trace("entry.gphoto.id = " + entry.gphoto.id);
			trace("entry.gphoto.version = " + entry.gphoto.version);
			trace("entry.gphoto.position = " + entry.gphoto.position);
			trace("entry.gphoto.albumid = " + entry.gphoto.albumid);
			trace("entry.gphoto.width = " + entry.gphoto.width);
			trace("entry.gphoto.height = " + entry.gphoto.height);
			trace("entry.gphoto.size = " + entry.gphoto.size);
			trace("entry.gphoto.client = " + entry.gphoto.client);
			trace("entry.gphoto.checksum = " + entry.gphoto.checksum);
			trace("entry.gphoto.timestamp = " + entry.gphoto.timestamp);
				
			trace("");
			
			trace("entry.exif.fstop = " + entry.exif.fstop);
			trace("entry.exif.make = " + entry.exif.make);
			trace("entry.exif.model = " + entry.exif.model);
			trace("entry.exif.exposure = " + entry.exif.exposure);
			trace("entry.exif.flash = " + entry.exif.flash);
			trace("entry.exif.focallength = " + entry.exif.focallength);
			trace("entry.exif.time = " + entry.exif.time);
			trace("entry.exif.imageUniqueID = " + entry.exif.imageUniqueID);

			trace("");
			
			trace("entry.media.title = " + entry.media.title);
			trace("entry.media.description = " + entry.media.description);
			trace("entry.media.keywords = " + entry.media.keywords);
			trace("entry.media.content = " + entry.media.content);
			trace("entry.media.thumbnail = " + entry.media.thumbnail);
			trace("entry.media.credit = " + entry.media.credit);
			
			trace("");
		}
	}
	
	private function handlerEntryOnError(evtObj:Object):Void{
		for(var i:String in evtObj){
			trace(i + " = " + evtObj[i]);
		}
	}
}